
require("./globalVariable/index.js")
const { app, BrowserWindow, session, ipcMain, Menu } = require('electron')
const { setMenumainWindow, MainMenu } = require('./menu/Menu.js')
const createWindow = () => {
    mainWindow = new BrowserWindow({
        width: 960,
        height: 560,
        // autoHideMenuBar: true,
        title: "流光科技",
        webPreferences: {
            contextIsolation: true, // 必须开启：隔离渲染进程与 Node.js 环境
            nodeIntegration: false,// 必须关闭：禁止渲染进程直接访问 Node.js API
            allowRunningInsecureContent: false,
            webSecurity: true,              // 启用 web 安全策略（防止跨域等风险）
            preload: path.join(__dirname, "preload.js")
        }
    })
    mainWindow.loadURL('https://aola.100bt.com/h5/')
    session.defaultSession.webRequest.onBeforeRequest((details, callback) => {
        if (details.url.indexOf(interceptUrl.GameMain) != -1) {
            callback({
                redirectURL: responseUrl.GameMain
            });
        } else {
            callback({ cancel: false })
        }
    })
    mainWindow.webContents.on('page-title-updated', (event, title) => {
        event.preventDefault();
        mainWindow.setTitle("流光科技");
    });
    setMenumainWindow(Menu, mainWindow, MainMenu)
    mainWindow.webContents.openDevTools()
}
global.createWindowChild = () => {
    mainWindowChild = new BrowserWindow({
        width: 600,
        height: 400,
        parent: mainWindow,
        webPreferences: {
            // contextIsolation: true, // 必须开启：隔离渲染进程与 Node.js 环境
            // nodeIntegration: false,// 必须关闭：禁止渲染进程直接访问 Node.js API
            // allowRunningInsecureContent: false,
            // webSecurity: true,              // 启用 web 安全策略（防止跨域等风险）
            preload: path.join(__dirname, "./preload.js")
        }
    })
    const isDev = process.argv.includes('--mode=development');
    if (isDev) {
        mainWindowChild.loadURL('http://localhost:5173/')
    } else {
        mainWindowChild.loadFile("dist/index.html")
    }
    mainWindowChild.webContents.openDevTools()
    mainWindowChildinstance = mainWindowChild
    mainWindowChild.on('close', (event) => {
        event.preventDefault();
        mainWindowChild.hide()
        mainWindowChildinstance = null
        console.log("关闭")
    })
}
app.whenReady().then(() => {
    createWindow()
    // createWindowChild()
})

app.on('activate', () => {
    if (BrowserWindow.getAllWindows().length === 0) createWindow()
})
app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') app.quit()
})
ipcMain.handle(Game.send, (event, data) => {
    mainWindowChild.webContents.send(Game.send, data)
})











